// @ts-ignore
import api from "@/api/http";
import { ApiResponse, ListResponse } from "@/api/types/ApiResponse";
import { SearchKeyQueryParam } from "@/api/types/QueryParam";


export interface SysTbResourceResponse {
  id: string,
  createTime: string,
  updateTime: string,
  createUserAccount: string,
  updateUserAccount: string,
  resourceName: string,
  resourceDescription: string,
  resourceUrl: string,
  resourceAppCode: string,
  iconDefault: string,
  fkParentId: string,
  resourceType: string,
  disabled: number,
  resourceCode: string,
  orderIndex: number,
  hasChildren?: boolean
  children?: SysTbResourceResponse[],
  resourceConfig: object,
}

export interface SelectSysTbResourcePageListQueryParam extends SearchKeyQueryParam {
  resourceType: string;
  resourceAppCode?: string;
}

/**
 * 分页查询列表
 * @param query
 */
export const selectSysTbResourcePageList = (query: SelectSysTbResourcePageListQueryParam): Promise<ListResponse<SysTbResourceResponse>> => {
  return api.doGet("/SysApp/SysTbResource/selectPageList", query);
};
export const selectSysTbResourceTreeList = (query: SelectSysTbResourcePageListQueryParam): Promise<ListResponse<SysTbResourceResponse>> => {
  console.log(query);
  return api.doGet("/SysApp/SysTbResource/selectTreeList", query);
};
/**
 * 根据ID查询
 * @param id
 */
export const selectSysTbResourceById = (id: string | number): Promise<ApiResponse<SysTbResourceResponse>> => {
  return api.doGet("/SysApp/SysTbResource/selectById", { id: id });
};
/**
 * 根据ID查询
 * @param id
 */
export const selectSysTbResourceByIds = (id: string[] | number[]): Promise<ListResponse<SysTbResourceResponse>> => {
  return api.doGet("/SysApp/SysTbResource/selectByIds", { ids: id.toString() });
};

/**
 * 新增
 * @param id
 */
export const doSaveSysTbResource = (data: any): Promise<ApiResponse<boolean>> => {
  return api.doPost("/SysApp/SysTbResource/save", data);
};
/**
 * 新增
 * @param id
 */
export const doSaveList = (data: any): Promise<ApiResponse<boolean>> => {
  return api.doPost("/SysApp/SysTbResource/saveList", data);
};
/**
 * 修改
 * @param id
 */
export const doUpdateSysTbResource = (data: any): Promise<ApiResponse<boolean>> => {
  return api.doPost("/SysApp/SysTbResource/update", data);
};
/**
 * 更新排序
 * @param data
 */
export const doUpdateOrderIndex = (data: any): Promise<ApiResponse<boolean>> => {
  return api.doPost("/SysApp/SysTbResource/updateOrderIndex", data);
};
/**
 * 逻辑删除
 * @param id
 */
export const doLogicDeleteSysTbResource = (ids: Array<string | number> | number | string): Promise<ApiResponse<boolean>> => {
  let data: any = null;
  if (Array.isArray(ids)) {
    data = ids;
  } else {
    data = [ids];
  }
  return api.doPost("/SysApp/SysTbResource/logicDelete", data);
};
/**
 * 物理删除
 * @param id
 */
export const doDeleteSysTbResource = (ids: Array<string> | number | string): Promise<ApiResponse<boolean>> => {
  let data: any = null;
  if (Array.isArray(ids)) {
    data = ids;
  } else {
    data = [ids];
  }
  return api.doPost("/SysApp/SysTbResource/delete", data);
};

export default {
  doUpdateOrderIndex,
  selectSysTbResourcePageList,
  selectSysTbResourceById,
  selectSysTbResourceByIds,
  doDeleteSysTbResource,
  doLogicDeleteSysTbResource,
  doUpdateSysTbResource,
  doSaveList,
  doSaveSysTbResource,
  selectSysTbResourceTreeList
};
